package com.mock.action.organisation.supportingmaterial;

import java.util.ArrayList;
import java.util.List;

import com.mock.action.AbstractAction;
import com.mock.dao.SupportingMaterialDao;
import com.mock.dao.impl.SupportingMaterialDaoImpl;
import com.mock.model.DataTable;
import com.mock.model.SupportingMaterial;

public class SupportingMaterialAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	public String setActive() {				
		SupportingMaterialDao supportingMaterialDao = new SupportingMaterialDaoImpl();
		SupportingMaterial supportingMaterial = supportingMaterialDao.getById(supportingMaterialId);
		supportingMaterial.setActive(true);
		supportingMaterialDao.update(supportingMaterial);
		return SUCCESS;
	}
	
	public String supportingMaterialTableAjax() {	
		long id = Long.parseLong(getRequest().getParameter("organisationId"));		
		DataTable dt = new DataTable();
		dt.sEcho = sEcho = getRequest().getParameter("sEcho");
		dt.iDisplayStart = iDisplayStart = Integer.parseInt(getRequest()
				.getParameter("iDisplayStart"));
		dt.iDisplayLength = iDisplayLength = Integer.parseInt(getRequest()
				.getParameter("iDisplayLength"));		
		dt.sSearch_5 = sSearch_5 = getRequest().getParameter("sSearch_5");		
		dt.iSortCol_0 = iSortCol_0 = Integer.parseInt(getRequest()
				.getParameter("iSortCol_0"));
		dt.sSortDir_0 = sSortDir_0 = getRequest().getParameter("sSortDir_0");
		dt.iTotalDisplayRecords = iTotalDisplayRecords = new SupportingMaterialDaoImpl().getRowCount();
		dt.iTotalRecords = iTotalRecords = new SupportingMaterialDaoImpl().getRowCount(SupportingMaterial.class);
		List<SupportingMaterial> supportingMaterials = new SupportingMaterialDaoImpl().getSupportingMaterialByQuery(dt, id);
		for (SupportingMaterial supportingMaterial : supportingMaterials) {
			ArrayList<String> newArray = new ArrayList<String>();
			newArray.add(supportingMaterial.getUrl());
			newArray.add(supportingMaterial.getDescription());
			newArray.add(supportingMaterial.getSupportingMaterialType().getType());
			newArray.add(supportingMaterial.getUser().getAccount());			
			newArray.add(supportingMaterial.getAddedDate().toString());			
			if (supportingMaterial.isActive()) {
				newArray.add("Yes");
			} else {
				newArray.add("No");
			}			
			newArray.add(Long.toString(supportingMaterial.getId()));			
			aaData.add(newArray);
		}
		return SUCCESS;
	}
	
	private List<ArrayList<String>> aaData = new ArrayList<ArrayList<String>>();
	private long organisationId = -1L;
	private long supportingMaterialId = -1L;
	private String sEcho;
	private String sSearch;
	private int iDisplayLength;
	private int iDisplayStart;
	private int iTotalRecords;
	private int iTotalDisplayRecords;
	private int iSortCol_0;
	private String sSortDir_0;
	private String sSearch_5;

	public List<ArrayList<String>> getAaData() {
		return aaData;
	}

	public void setAaData(List<ArrayList<String>> aaData) {
		this.aaData = aaData;
	}

	public long getOrganisationId() {
		return organisationId;
	}

	public void setOrganisationId(long organisationId) {
		this.organisationId = organisationId;
	}

	public long getSupportingMaterialId() {
		return supportingMaterialId;
	}

	public void setSupportingMaterialId(long supportingMaterialId) {
		this.supportingMaterialId = supportingMaterialId;
	}

	public String getsEcho() {
		return sEcho;
	}

	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}

	public String getsSearch() {
		return sSearch;
	}

	public void setsSearch(String sSearch) {
		this.sSearch = sSearch;
	}

	public int getiDisplayLength() {
		return iDisplayLength;
	}

	public void setiDisplayLength(int iDisplayLength) {
		this.iDisplayLength = iDisplayLength;
	}

	public int getiDisplayStart() {
		return iDisplayStart;
	}

	public void setiDisplayStart(int iDisplayStart) {
		this.iDisplayStart = iDisplayStart;
	}

	public int getiTotalRecords() {
		return iTotalRecords;
	}

	public void setiTotalRecords(int iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}

	public int getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}

	public void setiTotalDisplayRecords(int iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}

	public int getiSortCol_0() {
		return iSortCol_0;
	}

	public void setiSortCol_0(int iSortCol_0) {
		this.iSortCol_0 = iSortCol_0;
	}

	public String getsSortDir_0() {
		return sSortDir_0;
	}

	public void setsSortDir_0(String sSortDir_0) {
		this.sSortDir_0 = sSortDir_0;
	}

	public String getsSearch_5() {
		return sSearch_5;
	}

	public void setsSearch_5(String sSearch_5) {
		this.sSearch_5 = sSearch_5;
	}

}
